
function isType(type){
  return function(obj){
    // console.log(Object.prototype.toString.call(obj))
    return Object.prototype.toString.call(obj) == '[object '+ type +']';
  }
}

// let testType = {
//   isFunction: isType("function")
// }

function isTypeOf(type) {
    return function (obj) {
        return typeof obj === type;
    }
}
let isFunction = isType("Function");
let isUndefined = isType("Undefined");
let isArray = Array.isArray || isType("Array");
let isObject = isType('Object');
const isString = isType('String');

/**
 * 深度复制对象
 * @param {*} obj 
 */
function deepCopy (obj) {
  let result = obj;
  if (isArray(obj)) {
    result = [];
    for(let i = 0, len = obj.length; i < len; ++i) {
      result.push(deepCopy(obj[i]));
    }
  } else if (isObject(obj)) {
    result = {};
    for (let j in obj) {
      if (Object.hasOwnProperty.call(obj, j)) {
        result[j] = deepCopy(obj[j]);
      }
    }
  }
  return result;
}

export {
  isFunction,
  isUndefined,
  isArray,
  isObject,
  deepCopy
};
